package com.le.tester.book.effectivejava3rdchinese.secondReading.l10;

import com.google.common.collect.Sets;

import java.util.Set;

/**
 * createTime：2024-08-15 9:56
 * description：
 */
public class Point {

    private final int x;
    private final int y;

    private static final Set<Point> unitCircle = Sets.newHashSet(new Point(1, 0), new Point(0, 1),
            new Point(-1, 0), new Point(0, -1));

    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public boolean equals(Object obj) {
//        if (!(obj instanceof Point)) {
//            return false;
//        }
        //控制传递性
        if (obj == null || obj.getClass() != getClass()) {
            return false;
        }

        Point p = (Point) obj;
        return p.x == x && p.y == y;
    }

    public static boolean onUnitCircle(Point p) {
        return unitCircle.contains(p);
    }
}
